import java.util.Arrays;

public class note_arr {

    //1.数组初始化
    public static void main1(String[] args) {

        int[] arr1={12,3,4};
        System.out.println(arr1);

        int[] arr2=null;

        System.out.println(arr2);


    }

    //2.arr1指向arr2数组
    public static void main2(String[] args) {


        int[] arr1={1,2,3};
        System.out.println("初始时arr1：");
        for(int x:arr1){
            System.out.print(x+" ");
        }
        System.out.println();

        int[] arr2={10,30,60,90,120};
        System.out.println("初始时arr2：");
        for(int x:arr2){
            System.out.print(x+" ");
        }
        System.out.println();

        arr1=arr2;
        System.out.println("赋值后arr1：");
        for(int x:arr1){
            System.out.print(x+" ");
        }
        System.out.println();
        System.out.println("赋值后arr2：");
        for(int x:arr2){
            System.out.print(x+" ");
        }
    }

    //3.数组做返回值

    public static int[] add(int a,int b){
        int[] arr2={a,b};
        return arr2;


    }

    public static void main3(String[] args) {

        String s1 = Arrays.toString(add(3, 5));



        String s = Arrays.toString(add(3, 56));
        System.out.println(s);


    }


    //4.实现 Arrays.toString（）功能

    //1.Java的Arrays.toString（）返回值是一个String值
    public static String myTostring(int[] arr2){
        String ret="[";
        ret+=arr2[0];
        for(int i=1;i<arr2.length;i++){
            ret+=(","+arr2[i]);
        }
        ret+="]";
        return ret;
    }
    public static void main(String[] args) {

        int[] arr={1,2,3,4,5};
        System.out.println(myTostring(arr));
    }
}
